/**************************************************************************************************
* Title: SumColor.cpp
* Author: Gael Huber
* Description: Defines color functions
**************************************************************************************************/
#include "SumMath.h"

/**************************************************************************************************
* Interpolate r,g,b between desaturated color and color. 
* DesaturatedColor + s(Color - DesaturatedColor)
**************************************************************************************************/
Color* ColorAdjustSaturation(Color* pOut, const Color* pC, float s) {
	const float grey = pC->r*0.2125f + pC->g*0.7154f + pC->b*0.0721f;
	Color desat(grey, grey, grey, pC->a);
	Color diff;
	ColorSub(&diff, pC, &desat);
	ColorScale(&diff, &diff, s);
	ColorAdd(pOut, &desat, &diff);
	return pOut;
}

/**************************************************************************************************
* Interpolate r,g,b, between 50% grey and color. Grey + s(Color - Grey)
**************************************************************************************************/
Color* ColorAdjustContrast(Color* pOut, const Color* pC, float c) {
	pOut->r = 0.5f + c*(pC->r - 0.5f);
	pOut->g = 0.5f + c*(pC->g - 0.5f);
	pOut->b = 0.5f + c*(pC->b - 0.5f);
	pOut->a = pC->a;
	return pOut;
}